package com.huobao.yunying.activitys.muyingquan;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;import com.alipay.android.phone.mrpc.core.ad;
import com.huobao.yunying.adapters.Adapter_SheQu_ShouCang;
import com.huobao.yunying.https.Http;
import com.huobao.yunying.https.HttpListener;
import com.huobao.yunying.https.HttpUtil;

import android.content.Intent;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;

public class Act_SheQu_ShouCang extends Act_SheQu_Base implements OnItemClickListener{
	private Adapter_SheQu_ShouCang adapter;
	private List<SheQu_ShouCang> datas = new ArrayList<SheQu_ShouCang>();

	@Override
	protected void onInit() {
		adapter=new Adapter_SheQu_ShouCang(context);
		mListView.setAdapter(adapter);
		mListView.setOnItemClickListener(this);
		GetData();
	}

	private void GetData() {
		Map<String, String> map = HttpUtil.getParams("app", "mypost", "act", "collect_post");
		Http.getInstant().sendRequest(context, true, map, new HttpListener() {

			@Override
			public void onHttpSuccess(String result) {
				JSONObject jsonobject = JSON.parseObject(result);
				datas = JSON.parseArray(jsonobject.getString("retval"), SheQu_ShouCang.class);
				if (datas == null || datas.size() == 0) {
					Rel_empty.setVisibility(View.VISIBLE);
					mListView.setVisibility(View.GONE);
				} else {
					Rel_empty.setVisibility(View.GONE);
					mListView.setVisibility(View.VISIBLE);
					adapter.addAll(datas);
				}
			}

			@Override
			public void onHttpError(String error) {

			}
		});
	}

	@Override
	protected String getTitleText() {
		// TODO Auto-generated method stub
		return "我的收藏";
	}

	@Override
	public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
		Intent intent = new Intent(this, Act_Tiezi_Detail.class);
		intent.putExtra("id", adapter.getItem(position).getPid());
		intent.putExtra("quanziid", adapter.getItem(position).getGid());
		startActivity(intent);
	}

}
